import $store from '@/store/index.js';
import groupApi from "@/services/api/group.js"
import groupSqlite from "@/sqlite_services/group.js"
import groupMembersSqlite from '@/sqlite_services/group_members.js'
//群管理取消
const handle = async(data)=>{
	try{
		
		//更新store的群列表，前提是现在打开了群
		let updata = data.operatorsed_ids.map(item => ({ user_id: item, role:'member' }));
		
		//更新群成员资料
		$store.commit('updateGroupMembersInfo',{
			group_id:data.target_id,
			data:updata
		})
		
		let myid = $store.state.user.user_info.user_id
		//判断被执行人有没有自己，如果有就更新群聊资料中的 我的身份
		let index = data.operatorsed_ids.findIndex(item=>item == myid)
		if(index != -1){
			$store.commit('updateChatGroupInfo',{
				group_id:data.target_id,
				userRole:'member'
			})
			//更新数据库里的我的身份
			groupSqlite.editGroupInfo(data.target_id,{
				userRole:'member'
			})
		}
		//发送全局通知
		uni.$emit('onGroupMemberAction',{
			type:'managerCancel',
			data:{
				group_id:data.target_id,
				user_ids:data.operatorsed_ids
			}
		})
		groupMembersSqlite.batchEditGroupMembers(data.target_id,data.operatorsed_ids,{role:'member'})
	}catch(e){
		
	}
}
export default handle